import { Module, BadRequestException } from '@nestjs/common'
import { AvatarService } from './avatar.service'
import { AvatarController } from './avatar.controller'
import { TypeOrmModule } from '@nestjs/typeorm'
import { Avatar } from './entities/avatar.entity'
import { MulterModule } from '@nestjs/platform-express'

@Module({
  imports: [
    MulterModule.register({
      limits: {
        fileSize: 2 * 1024 * 1024 // 限制文件大小为 2MB
      },
      fileFilter: (_, file, cb) => {
        // 限制文件类型为图片
        if (!file.mimetype.match(/(jpg|jpeg|png)$/)) return cb(new BadRequestException('只允许上传 JPG, JPEG, PNG 格式的图片'), false)
        cb(null, true)
      }
    }),
    TypeOrmModule.forFeature([Avatar])
  ],
  controllers: [AvatarController],
  providers: [AvatarService]
})
export class AvatarModule {}
